package com.inno.subject.controller.controller;

import cn.hutool.core.bean.BeanUtil;
import com.inno.subject.common.entity.CommonReturnType;
import com.inno.subject.controller.dto.SubjectLevelDTO;
import com.inno.subject.domain.entity.SubjectLevelBO;
import com.inno.subject.domain.service.SubjectLevelDomainService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/subject/level")
public class SubjectLevelController {
    @Resource
    private SubjectLevelDomainService subjectLevelDomainService;

    @GetMapping("/queryList")
    public CommonReturnType<List<SubjectLevelDTO>> queryList(){
        List<SubjectLevelBO> subjectLevelBOList = subjectLevelDomainService.queryList();

        return CommonReturnType.success(convertBOListToDTOList(subjectLevelBOList));
    }

    private List<SubjectLevelDTO> convertBOListToDTOList(List<SubjectLevelBO> list){
        List<SubjectLevelDTO> result = new LinkedList<>();
        for (SubjectLevelBO item : list) {
           SubjectLevelDTO subjectLevelDTO = new SubjectLevelDTO();
            BeanUtil.copyProperties(item,subjectLevelDTO);
            result.add(subjectLevelDTO);
        }
        return result;

    }
}
